/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webanovare.model.db;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 *
 * @author jarmju
 */
@Entity
public class PlayedGame implements Serializable {
    
    @Id
    private Long id;
    
    private User owner;
    private User opponent;
    
    private int winnerPoints;
    private int loserPoints;
    private List<String> winnerWords;
    private List<String> loserWords;
    
    private boolean ownerWon;
    
    public PlayedGame() {}
    
    public PlayedGame(Long gid, User owner, User opponent, 
            int winnerPoints, int loserPoints, List<String> winnerWords, List<String> loserWords, boolean ownerWon) {
        this.id = gid;
        this.owner = owner;
        this.opponent = opponent;
        this.winnerPoints = winnerPoints;
        this.loserPoints = loserPoints;
        this.winnerWords = winnerWords;
        this.loserWords = loserWords;
        this.ownerWon = ownerWon;
    }
    
    public Long getId() {
        return this.id;
    }
    
    public User getOwner() {
        return this.owner;
    }
    
    public User getOpponent() {
        return this.opponent;
    }
    
    public User getWinner() {
        if (ownerWon) {
            return this.owner;
        }
        else {
            return this.opponent;
        }
    }
    
    public User getLoser() {
        if (ownerWon) {
            return this.opponent;
        }
        else {
            return this.owner;
        }
    }
    
    public User getOtherPlayer(String me) {
        if (me.equals(owner.getUsername())) {
            return opponent;
        }
        else if (me.equals(opponent.getUsername())) {
            return owner;
        }
        else {
            return null;
        }
    }
    
    public int getWinnerPoints() {
        return this.winnerPoints;
    }
    
    public int getLoserPoints() {
        return this.loserPoints;
    }
    
    public List<String> getWinnerWords() {
        return this.winnerWords;
    }
    
    public List<String> getLoserWords() {
        return this.loserWords;
    }
    
    public int getPointsByUserName(String name) {
        if (this.getWinner().getUsername().equals(name)) {
           return this.getWinnerPoints(); 
        }
        else {
            return this.getLoserPoints();
        }
    }
    
    public List<String> getWordsByUserName(String name) {
        if (this.getWinner().getUsername().equals(name)) {
           return this.getWinnerWords(); 
        }
        else {
            return this.getLoserWords();
        }
    }
    
}
